
/****** Object:  Table [dbo].[Document]     ******/
CREATE TABLE [dbo].[Document](
	[Id] [int] NOT NULL,
	[Name] [char](255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
 CONSTRAINT [PK_Document] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]


/****** Object:  Table [dbo].[Path]     ******/
CREATE TABLE [dbo].[Path](
	[PathId] [int] NOT NULL,
	[PathExp] [char](255) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
 CONSTRAINT [PK_Path] PRIMARY KEY CLUSTERED 
(
	[PathId] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

CREATE UNIQUE NONCLUSTERED INDEX [IX_Path] ON [dbo].[Path] 
(
	[PathExp] ASC
)WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF) ON [PRIMARY]


/****** Object:  Table [dbo].[DocumentRValue]    ******/
CREATE TABLE [dbo].[DocumentRValue](
	[DocId] [int] NOT NULL,
	[Level] [int] NOT NULL,
	[RValue] [bigint] NULL,
 CONSTRAINT [PK_DocumentRValue] PRIMARY KEY CLUSTERED 
(
	[DocId] ASC,
	[Level] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]


/****** Object:  Table [dbo].[PathValue]     ******/
CREATE TABLE [dbo].[PathValue](
	[DocId] [int] NOT NULL,
	[LeafOrder] [int] NOT NULL,
	[BranchOrder] [int] NULL,
	[PathId] [int] NULL,
	[DeweyOrderSum] [bigint] NOT NULL,
	[SiblingSum] [bigint] NULL,
	[LeafValue] [varchar](768) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]

CREATE UNIQUE INDEX [IX_PathValue_1] ON [dbo].[PathValue] 
(
	[DocId] ASC,
	[PathId] ASC,
	[DeweyOrderSum] ASC
)WITH (STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = OFF) ON [PRIMARY]

CREATE CLUSTERED INDEX [IX_PathValue_2] ON [dbo].[PathValue] 
(
	[PathId] ASC,
	[BranchOrder] ASC
)WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF) ON [PRIMARY]

CREATE NONCLUSTERED INDEX [IX_PathValue_3] ON [dbo].[PathValue] 
(
	[PathId] ASC
)WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF) ON [PRIMARY]


CREATE NONCLUSTERED INDEX [IX_PathValue_4] ON [dbo].[PathValue] 
(
	[LeafValue] ASC,
	[PathId] ASC
)WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF) ON [PRIMARY]


/****** Object:  Table [dbo].[Attribute]     ******/
CREATE TABLE [dbo].[Attribute](
	[DocId] [int] NOT NULL,
	[LeafOrder] [int] NOT NULL,
	[PathId] [int] NOT NULL,
	[AttrOrder] [int] NOT NULL,
	[LeafValue] [varchar](768) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]

CREATE UNIQUE CLUSTERED INDEX [IX_Attribute_1] ON [dbo].[Attribute] 
(
	[DocId] ASC,
	[LeafOrder] ASC,
	[PathId] ASC
)WITH (STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = OFF) ON [PRIMARY]

CREATE NONCLUSTERED INDEX [IX_Attribute_2] ON [dbo].[Attribute] 
(
	[PathId] ASC
)WITH (SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF) ON [PRIMARY]




/****** Object:  Table [dbo].[TextContent]     ******/
CREATE TABLE [dbo].[TextContent](
	[DocId] [int] NOT NULL,
	[LeafOrder] [int] NOT NULL,
	[BranchOrder] [int] NULL,
	[PathId] [int] NULL,
	[DeweyOrderSum] [bigint] NOT NULL,
	[SiblingSum] [bigint] NULL,
	[LeafValue] [varchar](768) COLLATE SQL_Latin1_General_CP1_CI_AS NULL
) ON [PRIMARY]

CREATE UNIQUE CLUSTERED INDEX [IX_TextContent_1] ON [dbo].[TextContent] 
(
	[DocId] ASC,
	[PathId] ASC,
	[DeweyOrderSum] ASC
)WITH (STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = OFF) ON [PRIMARY]


/****** Object:  Table [dbo].[AttrContent]     ******/
CREATE TABLE [dbo].[AttrContent](
	[DocId] [int] NOT NULL,
	[LeafOrder] [int] NOT NULL,
	[PathId] [int] NOT NULL,
	[AttrOrder] [int] NOT NULL,
	[LeafValue] [varchar](768) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]

CREATE UNIQUE CLUSTERED INDEX [IX_AttrContent_1] ON [dbo].[AttrContent] 
(
	[DocId] ASC,
	[LeafOrder] ASC,
	[PathId] ASC
)WITH (STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = OFF) ON [PRIMARY]

/****** Statistics Table     ******/
/****** Object:  Table [dbo].[PathCount_ValueSelectivity]     ******/
CREATE TABLE [dbo].[PathCount_ValueSelectivity](
	[pathid] [int] NULL,
	[CP] [int] NULL,
	[VP] [int] NULL
) ON [PRIMARY]

/****** Object:  Table [dbo].[TotalPathCount]   ******/
CREATE TABLE [dbo].[TotalPathCount](
	[T] [int] NULL
) ON [PRIMARY]


CREATE TABLE [dbo].[PVTemp](
	[LeafValue] [varchar](max) NULL,
	[PathID] [int] NULL,
	[BranchOrder] [int] NULL,
	[DeweyOrderSum] [bigint] NULL,
	[DocId] [int] NULL,
	[LeafOrder] [int] NULL
) ON [PRIMARY]


CREATE NONCLUSTERED INDEX [DocID_LeafOrder] ON [dbo].[PVTemp] 
(
	[LeafOrder] ASC,
	[DocId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]


CREATE TABLE [dbo].[DescendantTemp](
	[DescendantId] [int] NOT NULL,
	[PathId] [int] NOT NULL,
	[Level] [int] NOT NULL,
 CONSTRAINT [PK_DescendantTemp] PRIMARY KEY CLUSTERED 
(
	[PathId] ASC,
	[DescendantId] ASC,
	[Level] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]


CREATE TABLE [dbo].[AncestorTemp](
	[PathId] [int] NOT NULL,
	[AncestorId] [int] NOT NULL,
	[Level] [int] NOT NULL,
	[AnceBranchOrd] [int] NOT NULL,
 CONSTRAINT [PK_AncestorTemp] PRIMARY KEY CLUSTERED 
(
	[PathId] ASC,
	[AncestorId] ASC,
	[Level] ASC
)WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]


CREATE TABLE [dbo].[LastTemp](
	[RID] [int] NOT NULL,
	[DocID] [int] NOT NULL,
	[SiblingSum] [bigint] NOT NULL,
	[Flag] [smallint] NOT NULL,
	[DeweyOrderSum] [bigint] NULL,
	[PDOS] [bigint] NULL
) ON [PRIMARY]


CREATE CLUSTERED INDEX [Idx] ON [dbo].[LastTemp] 
(
	[Flag] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]